package com.legrandgourmet.android.promocion;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class CarrerasActivity extends Activity implements OnClickListener {

	Resources rs;
	
	MenuItem inicio;
	MenuItem cursos;
	MenuItem premios;
	MenuItem sedes;
	
	Button button1;
	Button button2;
	Button button3;
	Button button4;
	Dialog dialog;
	String[] names = new String[] { "Chef de Cocina Internacional", "Bartender Internacional",
			"Gastronomía y Arte Culinario", "Administración de Servicios de Hoteleria" };
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_carreras); 
        rs = this.getResources();
        
        button1 = (Button) findViewById(R.id.btncarrera1);
        button1.setOnClickListener(this);
        button2 = (Button) findViewById(R.id.btncarrera2);
        button2.setOnClickListener(this);
        button3 = (Button) findViewById(R.id.btncarrera3);
        button3.setOnClickListener(this);
        button4 = (Button) findViewById(R.id.btncarrera4);
        button4.setOnClickListener(this);
       /* ListView listView = getListView();
		listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_single_choice,
				android.R.id.text1, names));*/
        
       /* ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				R.layout.rowlayout, R.id.label, names);
		setListAdapter(adapter);*/
        
       /* setContentView( R.layout.layout_carreras );
     
        List<Map<String, String>> data =
            new ArrayList<Map<String,String>>();
        for( int i = 1; i <= 10; i++ )
        {
            Map<String, String> item =
                new HashMap<String, String>();
            item.put( "name", String.format( "Item %d", i ) );
            data.add( item );
        }
     
        String[] from = { "name" };
        int[] to = { android.R.id.text1 };
     
        SimpleAdapter adapter = new SimpleAdapter( this, data,
            android.R.layout.simple_list_item_1, from, to );
        setListAdapter( adapter );*/

		
    }

	@Override
	public void onClick(View view) {
		if(view == button1){
    		createDialog(1);
    	}
		if(view == button2){
    		createDialog(2);
    	}
		if(view == button3){
    		createDialog(3);
    	}
		if(view == button4){
    		createDialog(4);
    	}
	}
	

	private void createDialog(int carrera) {
		//set up dialog
        dialog = new Dialog(this);
        dialog.setContentView(R.layout.layout_dialogo_carrera);
       // dialog.setTitle(names[carrera-1]);
        dialog.setCancelable(true);
        //there are a lot of settings, for dialog, check them all out!

        //set up text
        TextView textTitulo = (TextView) dialog.findViewById(R.id.TextViewTitulo);
        textTitulo.setText(names[carrera-1]);
        TextView text = (TextView) dialog.findViewById(R.id.TextViewDialog);
        //set up image view
        ImageView img = (ImageView) dialog.findViewById(R.id.ImageViewDialog);
        switch (carrera) {
		case 1:{
			text.setText(R.string.chefInterTxt);
			img.setImageResource(R.drawable.chefinternacional);
			break;
		}
		case 2:{
			text.setText(R.string.barInterTxt);
			img.setImageResource(R.drawable.barinternacional);
			break;
		}	
		case 3:{
			text.setText(R.string.gastronomiaArteTxt);
			img.setImageResource(R.drawable.gastronomia);
			break;
		}
		case 4:{
			text.setText(R.string.adminHoteleriaTxt);
			img.setImageResource(R.drawable.adminhotel);
			break;
		}
		default:{
			text.setText(R.string.chefInterTxt);
			img.setImageResource(R.drawable.chefinternacional);
			break;
		}
		}
      

        
       

        //set up button
        Button button = (Button) dialog.findViewById(R.id.ButtonDialog);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	dialog.dismiss();
            }
        });
        //now that the dialog is set up, it's time to show it    
        dialog.show();
	}

	/*@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Log.i("position",""+position+" "+names.length);

		if(position - 1>=0 && position - 1 <= names.length - 1){
			String item = (String) getListAdapter().getItem(position - 1);
			Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
		}
	}*/
	/*@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		String item = (String) getListAdapter().getItem(position);
		Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
	}*/
	
	@Override  
    public boolean onCreateOptionsMenu(Menu menu) {
    	inicio = menu.add(rs.getString(R.string.inicio));
    	inicio.setIcon(R.drawable.icono_inicio);
    	
	  	cursos = menu.add(rs.getString(R.string.cursos));
	  	cursos.setIcon(R.drawable.icono_cursos);
	  	
	  	premios = menu.add(rs.getString(R.string.premios));
	  	premios.setIcon(R.drawable.icono_trofeo);
	  	
	  	sedes = menu.add(rs.getString(R.string.sedes));
	  	sedes.setIcon(R.drawable.icono_sedes);
	  	
	  	return super.onCreateOptionsMenu(menu); 
    }
	
	@Override 
 	public boolean onOptionsItemSelected(MenuItem item) {
	     	Intent i;
	     	
	     	if(item.equals(inicio)){
	     		i = new Intent(this,DescripcionActivity.class);
		  		startActivity(i);
		  	    finish();
	     	}
	     	
	     	if(item.equals(cursos)){
	     		i = new Intent(this,CursosActivity.class);
		      	startActivity(i);
		      	finish();
	     	}
	     	
	     	if(item.equals(premios)){
	     		i = new Intent(this,PremiosActivity.class);
		      	startActivity(i);
		      	finish();
	     	}
	     	
	     	if(item.equals(sedes)){
	     		i = new Intent(this,SedesActivity.class);
		      	startActivity(i);
		      	finish();
	     	}
	     	
	     	return false;
    }

}